<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style type="text/css">

        /* tooltip */
        #tooltip{
            position:absolute;
            border:1px solid #ccc;
            background:#333;
            padding:2px;
            display:none;
            color:#fff;
        }
    </style>
</head>
<body style="margin: 0 20px">

<fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;border:0">
    <form class="layui-form serch" >
        <div class="layui-form-item" style="float: left;">
            <a href="{:url('tripprice/addtype')}" class="layui-btn layui-btn-sm a_menu">
                添加价格类型
            </a>
        </div>
    </form>
</fieldset>

<table class="layui-table" lay-even="" lay-skin="row" lay-size="sm">
    <colgroup>
        <col width="50">
        <col width="100">
        <col width="100">
        <col width="150">
        <col width="150">
        <col width="150">
        <col width="150">
        <col width="200">
    </colgroup>
    <thead>
    <tr>
        <th>ID</th>
        <th>价格类型</th>
        <th>默认价格</th>
        <th>二级配置</th>
        <th>创建时间</th>
        <th>修改时间</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {volist name="info" id="vo"}
    <tr>
        <td>{$vo.price_type_id}</td>
        <td>{$vo.type_name}</td>
        <td>{$vo.value}</td>
        <td>{$vo.childprice}</td>
        <td>{$vo.creattime}</td>
        <td>{$vo.updatetime}</td>
        <td>{if condition='$vo.type_status eq 1'}使用中{else}已停用{/if}</td>
        <td class="operation-menu">
            <a href="{:url('tripprice/addtype',['price_type_id'=>$vo.price_type_id])}" class="layui-btn layui-btn-xs a_menu"  style="margin-right: 0;font-size:12px;">修改</a>
            {if condition='$vo.type_status eq 1'}
            <a class="layui-btn layui-btn-xs delete" data-id="{$vo.price_type_id}" style="margin-right: 0;font-size:12px;">停用</a>
            {else}
            <a class="layui-btn layui-btn-xs layui-btn-danger start" data-id="{$vo.price_type_id}" style="margin-right: 0;font-size:12px;">启用</a>
            {/if}
            <a href="{:url('tripprice/addchild',['price_type_id'=>$vo.price_type_id])}" data-value="{$vo.type_name}" class="layui-btn layui-btn-xs add_child" style="margin-right: 0;font-size:12px;">二级配置</a>
        </td>
    </tr>
    {/volist}
    </tbody>
</table>

<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    var message;
    layui.config({
        base: '__JS__/',
        version: '1.0.1'
    }).use(['app', 'message'], function() {
        var app = layui.app,
            $ = layui.jquery,
            layer = layui.layer;
        //将message设置为全局以便子页面调用
        message = layui.message;
        //主入口
        app.set({
            type: 'iframe'
        }).init();
    });
</script>
<script type="text/javascript">
    $('.delete').click(function(){
        var id = $(this).attr('data-id');
        layer.confirm('确定要停用吗?', function(index) {
            $.ajax({
                url:"{:url('admin/tripprice/delete')}",
                data:{
                    id:id,
                    status:2
                },
                success:function(res) {
                    layer.msg(res.msg);
                    if(res.code == 1) {
                        setTimeout(function(){
                            location.href = res.url;
                        },1500)
                    }
                }
            })
        })
    })


    $('.start').click(function(){
        var id = $(this).attr('data-id');
        layer.confirm('确定要启用吗?', function(index) {
            $.ajax({
                url:"{:url('admin/tripprice/delete')}",
                data:{
                    id:id,
                    status:1
                },
                success:function(res) {
                    layer.msg(res.msg);
                    if(res.code == 1) {
                        setTimeout(function(){
                            location.href = res.url;
                        },1500)
                    }
                }
            })
        })
    })


</script>
<script type="text/javascript">
    layui.use('layer', function(){
        var layer = layui.layer;
        $('.a_menu').click(function(){
            var url = $(this).attr('href');
            var a = 0;
            $.ajax({
                url:url
                ,async:false
                ,success:function(res){
                    if(res.code == 0) {
                        layer.msg(res.msg);
                        a = 1;
                    }
                }
            })
            if(a === 0) {
                layer.open({
                    type:2,
                    content:[url, 'no'],
                    area: ['500px', '300px'],
                    end:function(){
                        location.reload();
                    }
                });
            }
            return false;
        })

        //打开二级配置页面
        $('.add_child').click(function(){
            var url = $(this).attr('href');
            var name = $(this).attr('data-value');
            layer.open({
                type:2,
                title:name+" - 二级配置",
                content:[url, 'no'],
                area: ['700px', '500px'],
                end:function(){
                    location.reload();
                }
            });

            return false;
        })
    });
</script>
</body>
</html>
